package edu.szu.huhanpeng.doodlingFight.model.data 
{
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import edu.szu.huhanpeng.doodlingFight.interfaces.IChessData;
	import edu.szu.huhanpeng.doodlingFight.interfaces.ISquareData;
	/**
	 * 对应棋盘上的每一格
	 * @author Huhanpeng
	 */
	public class SquareData implements ISquareData
	{
		//该方格在棋盘中的行，列
		private var _row:int;
		private var _column:int;
		
		//方格上的棋子状态
		private var _chessData:IChessData;
		
		private var _index:int;					//方格的编号，从0开始左到右，上到下排列
		private var _upSquare:ISquareData;		//上方的格子的引用
		private var _downSquare:ISquareData;	//下方的格子的引用
		private var _leftSquare:ISquareData;	//左方的格子的引用
		private var _rightSquare:ISquareData;	//右方的格子的引用
		
		private var _LUSquare:ISquareData;		//左上方的格子的引用
		private var _RUSquare:ISquareData;		//右上方的格子的引用
		private var _LDSquare:ISquareData;		//左下方的格子的引用
		private var _RDSquare:ISquareData;		//右下方的格子的引用
		
		/////////////////////////////////////////////////////////////////////
		//getter setter                                                    //
		/////////////////////////////////////////////////////////////////////
		public function get row():int
		{
			return _row;
		}
		
		public function get column():int
		{
			return _column;
		}
		
		public function get chessData():IChessData
		{
			return _chessData;
		}
		
		public function set chessData(data:IChessData):void
		{
			_chessData = data;
		}
		
		public function get index():int
		{
			return _index;
		}
		
		public function get upSquare():ISquareData 
		{
			return _upSquare;
		}
		
		public function set upSquare(value:ISquareData):void 
		{
			if (_upSquare != null) 
			{
				if (GlobalConst.setting.DEBUG) 
				{
					throw new Error("只在初始化时赋值");
				}
				return;
			}
			_upSquare = value;
		}
		
		public function get downSquare():ISquareData 
		{
			return _downSquare;
		}
		
		public function set downSquare(value:ISquareData):void 
		{
			if (_downSquare != null) 
			{
				if (GlobalConst.setting.DEBUG) 
				{
					throw new Error("只在初始化时赋值");
				}
				return;
			}
			_downSquare = value;
		}
		
		public function get leftSquare():ISquareData 
		{
			return _leftSquare;
		}
		
		public function set leftSquare(value:ISquareData):void 
		{
			if (_leftSquare != null) 
			{
				if (GlobalConst.setting.DEBUG) 
				{
					throw new Error("只在初始化时赋值");
				}
				return;
			}
			_leftSquare = value;
		}
		
		public function get rightSquare():ISquareData 
		{
			return _rightSquare;
		}
		
		public function set rightSquare(value:ISquareData):void 
		{
			if (_rightSquare != null) 
			{
				if (GlobalConst.setting.DEBUG) 
				{
					throw new Error("只在初始化时赋值");
				}
				return;
			}
			_rightSquare = value;
		}
		
		public function get LUSquare():ISquareData 
		{
			return _LUSquare;
		}
		
		public function set LUSquare(value:ISquareData):void 
		{
			if (_LUSquare != null) 
			{
				if (GlobalConst.setting.DEBUG) 
				{
					throw new Error("只在初始化时赋值");
				}
				return;
			}
			_LUSquare = value;
		}
		
		public function get RUSquare():ISquareData 
		{
			return _RUSquare;
		}
		
		public function set RUSquare(value:ISquareData):void 
		{
			if (_RUSquare != null) 
			{
				if (GlobalConst.setting.DEBUG) 
				{
					throw new Error("只在初始化时赋值");
				}
				return;
			}
			_RUSquare = value;
		}
		
		public function get LDSquare():ISquareData 
		{
			return _LDSquare;
		}
		
		public function set LDSquare(value:ISquareData):void 
		{
			if (_LDSquare != null) 
			{
				if (GlobalConst.setting.DEBUG) 
				{
					throw new Error("只在初始化时赋值");
				}
				return;
			}
			_LDSquare = value;
		}
		
		public function get RDSquare():ISquareData 
		{
			return _RDSquare;
		}
		
		public function set RDSquare(value:ISquareData):void 
		{
			if (_RDSquare != null) 
			{
				if (GlobalConst.setting.DEBUG) 
				{
					throw new Error("只在初始化时赋值");
				}
				return;
			}
			_RDSquare = value;
		}
		
		/////////////////////////////////////////////////////////////////////
		//构造函数                                                         //
		/////////////////////////////////////////////////////////////////////
		/**
		 * 
		 * @param	row		第几行
		 * @param	column  第几列
		 */
		public function SquareData(row:int, column:int, size:int) 
		{
			_row = row;
			_column = column;
			_index = row * size + column;
		}
		
		/////////////////////////////////////////////////////////////////////
		//接口                                                             //
		/////////////////////////////////////////////////////////////////////
		public function placeChess(chessData:IChessData):void
		{
			//解除移入棋子的原方格的关联
			if (chessData.square != null) 
			{
				chessData.square.chessData = null;
			}
			
			//接触现有棋子的关联
			if (_chessData != null) 
			{
				_chessData.square = null;
			}
			
			_chessData = chessData;
			chessData.square = this;
			chessData.updatePosData(_row, _column);
		}
		
		/////////////////////////////////////////////////////////////////////
		//内部                                                             //
		/////////////////////////////////////////////////////////////////////


		

		
	}

}